script(type='text/javascript').
	window.recurlyApiKey = "!{settings.apis.recurly.publicKey}"
	window.subscription = !{StringHelper.stringifyJsonForScript(personalSubscription)}
	window.recomendedCurrency = "#{personalSubscription.recurly.currency}"

div(ng-controller="RecurlySubscriptionController")
	div(ng-show="!showCancellation")
		case personalSubscription.recurly.state
			when "active"
				p !{translate("currently_subscribed_to_plan", {planName:"<strong>" + personalSubscription.plan.name + "</strong>"})}
					a(href, ng-click="switchToChangePlanView()", ng-if="showChangePlanButton") !{translate("change_plan")}.
				-if (personalSubscription.recurly.trialEndsAtFormatted && personalSubscription.recurly.trial_ends_at > Date.now())
					p You're on a free trial which ends on <strong ng-non-bindable>#{personalSubscription.recurly.trialEndsAtFormatted}</strong>
				p !{translate("next_payment_of_x_collectected_on_y", {paymentAmmount:"<strong>" + personalSubscription.recurly.price + "</strong>", collectionDate:"<strong>" + personalSubscription.recurly.nextPaymentDueAt + "</strong>"})}
				include ./../_price_exceptions
				p.pull-right
				p
					a(href=personalSubscription.recurly.billingDetailsLink, target="_blank").btn.btn-info #{translate("update_your_billing_details")}
					| &nbsp;
					a(href=personalSubscription.recurly.accountManagementLink, target="_blank").btn.btn-info #{translate("view_your_invoices")}
					| &nbsp;
					a(href, ng-click="switchToCancellationView()", ng-hide="recurlyLoadError").btn.btn-danger !{translate("cancel_your_subscription")}
			when "canceled"
				p !{translate("currently_subscribed_to_plan", {planName:"<strong>" + personalSubscription.plan.name + "</strong>"})}
				p !{translate("subscription_canceled_and_terminate_on_x", {terminateDate:"<strong>" + personalSubscription.recurly.nextPaymentDueAt + "</strong>"})}
				p
					a(href=personalSubscription.recurly.accountManagementLink, target="_blank").btn.btn-info #{translate("view_your_invoices")}
					p: form(action="/user/subscription/reactivate",method="post")
						input(type="hidden", name="_csrf", value=csrfToken)
						input(type="submit",value="Reactivate your subscription").btn.btn-success
			when "expired"
				p !{translate("your_subscription_has_expired")}
				p
					a(href=personalSubscription.recurly.accountManagementLink, target="_blank").btn.btn-info #{translate("view_your_invoices")}
					| &nbsp;
					a(href="/user/subscription/plans").btn.btn-success !{translate("create_new_subscription")}
			default
				p !{translate("problem_with_subscription_contact_us")}

		.alert.alert-warning(ng-show="recurlyLoadError")
			strong #{translate('payment_provider_unreachable_error')}

	include ./_change_plans_mixins
	div(ng-show="showChangePlan", ng-cloak)
		h2 !{translate("change_plan")}
		p: table.table
			tr
				th !{translate("name")}
				th !{translate("price")}
				th
			+printPlans(plans.studentAccounts)
			+printPlans(plans.individualMonthlyPlans)
			+printPlans(plans.individualAnnualPlans)


	.div(ng-controller="RecurlyCancellationController", ng-show="showCancellation").text-center
		p
			strong #{translate("sure_you_want_to_cancel")}

		div(ng-show="showExtendFreeTrial")
			p !{translate("have_more_days_to_try", {days:14})}
			p
				button(type="submit", ng-click="extendTrial()", ng-disabled='inflight').btn.btn-success #{translate("ill_take_it")}
			p
				a(href, ng-click="cancelSubscription()", ng-disabled='inflight') #{translate("no_thanks_cancel_now")}

		div(ng-show="showDowngradeToStudent")
			div(ng-controller="ChangePlanFormController")
				p !{translate("interested_in_cheaper_plan",{price:'{{studentPrice}}'})}
				p
					button(type="submit", ng-click="downgradeToStudent()", ng-disabled='inflight').btn.btn-info #{translate("yes_please")}
				p
					a(href, ng-click="cancelSubscription()", ng-disabled='inflight')  #{translate("no_thanks_cancel_now")}

		div(ng-show="showBasicCancel")
			p
				a(href, ng-click="switchToDefaultView()").btn.btn-info #{translate("i_want_to_stay")}
			p
				a(href, ng-click="cancelSubscription()", ng-disabled='inflight').btn.btn-primary #{translate("cancel_my_account")}

script(type="text/javascript").
	$('#cancelSubscription').on("click", function() {
		ga('send', 'event', 'subscription-funnel', 'cancelation')
	})

script(type='text/ng-template', id='confirmChangePlanModalTemplate')
	.modal-header
		h3 #{translate("change_plan")}
	.modal-body
		p !{translate("sure_you_want_to_change_plan", {planName:"<strong>{{plan.name}}</strong>"})}
	.modal-footer
		button.btn.btn-default(
			ng-disabled="inflight"
			ng-click="cancel()"
		) #{translate("cancel")}
		button.btn.btn-success(
			ng-disabled="state.inflight"
			ng-click="confirmChangePlan()"
		)
			span(ng-hide="inflight") #{translate("change_plan")}
			span(ng-show="inflight") #{translate("processing")}...

